{extends file="index.tpl"}
{block name="page-content"}

<script type="text/javascript">
$(document).ready(function()
{
	$(".edit_tr").click(function()
	{
		var ID=$(this).attr('id');
		$("#gameorder_"+ID).hide();
		$("#isevent_"+ID).hide();
		$("#hotstar_"+ID).hide();
		$("#name_"+ID).hide();
		$("#mediumname_"+ID).hide();
		$("#uniquename_"+ID).hide();
		$("#type_"+ID).hide();
		$("#link_canonical_"+ID).hide();
		
		$("#gameorder_input_"+ID).show();
		$("#isevent_input_"+ID).show();
		$("#hotstar_input_"+ID).show();
		$("#name_input_"+ID).show();
		$("#mediumname_input_"+ID).show();
		$("#uniquename_input_"+ID).show();
		$("#type_input_"+ID).show();
		$("#link_canonical_input_"+ID).show();
	}).change(function()
	{
		var ID=$(this).attr('id');
		var gameorder=$("#gameorder_input_"+ID).val();
		var isevent=$("#isevent_input_"+ID).val();
		var hotstar=$("#hotstar_input_"+ID).val();
		var name=$("#name_input_"+ID).val();
		var mediumname=$("#mediumname_input_"+ID).val();
		var uniquename=$("#uniquename_input_"+ID).val();
		var type=$("#type_input_"+ID).val();
		var linkCanonical=$("#link_canonical_input_"+ID).val();
		
		var dataString = 'id='+ ID +'&gameorder='+gameorder+'&isevent='+isevent+'&hotstar='+hotstar+'&name='+name+'&mediumname='+mediumname+'&uniquename='+uniquename+'&type='+type+'&linkCanonical='+linkCanonical+'&database={if isset($data)}{$data}{else}tpg{/if}';
		
		$("#gameorder_"+ID).html('<img src="http://thanhphogame.com/admin/view/img/load.gif" />');
		$("#isevent_"+ID).html('<img src="http://thanhphogame.com/admin/view/img/load.gif" />');
		$("#hotstar_"+ID).html('<img src="http://thanhphogame.com/admin/view/img/load.gif" />');		
		$("#name_"+ID).html('<img src="http://thanhphogame.com/admin/view/img/load.gif" />');
		$("#mediumname_"+ID).html('<img src="http://thanhphogame.com/admin/view/img/load.gif" />');
		$("#uniquename_"+ID).html('<img src="http://thanhphogame.com/admin/view/img/load.gif" />');	
		$("#type_"+ID).html('<img src="http://thanhphogame.com/admin/view/img/load.gif" />');	
		$("#link_canonical_"+ID).html('<img src="http://thanhphogame.com/admin/view/img/load.gif" />');	
		
		$.ajax({
			type: "POST",
			url: 'http://thanhphogame.com/admin/controller/process/ajaxEditTableGame.php',
			data: dataString,
			cache: false,
			success: function(html)
			{
				$("#gameorder_"+ID).html(gameorder);
				$("#isevent_"+ID).html(isevent);
				$("#hotstar_"+ID).html(hotstar);
				$("#name_"+ID).html(name);
				$("#mediumname_"+ID).html(mediumname);
				$("#uniquename_"+ID).html(uniquename);
				$("#type_"+ID).html(type);
				$("#link_canonical_"+ID).html(linkCanonical);
			}
		});		
	});
	
	$(".editbox").mouseup(function() {
		return false
	});
	
	$(document).mouseup(function(){
		$(".editbox").hide();
		$(".text").show();
	});

});
</script>

{literal}
<style>
	.editbox
	{
		display:none;
	}
	.editbox
	{
		font-size:14px;
		width: 70px;
		background-color:#ffffcc;
		border:solid 1px #000;
		padding:4px;
	}
	.edit_tr:hover
	{
		background:url(http://thanhphogame.com/admin/view/img/edit.png) right no-repeat #80C8E5;
		cursor:pointer;
	}

</style>
{/literal}

<div class="row-fluid">
    <div class="span12">
        <div class="block">
        	<div class="row-form">
        		<form method="POST" action="{$WEB_BASE_URL}/index.php?controller=game&action=list&database={if isset($data)}{$data}{else}tpg{/if}&filter=filter">
					<div class="span3">
						<select name="filter" class="select" style="width: 100%;">
							<option value="1">Is Event</option>
							<option value="5">Hot Star</option>
						</select>
					</div>&nbsp;&nbsp;&nbsp;
					<button class="btn btn-primary" type="submit">&nbsp;&nbsp;&nbsp;&nbsp;Fillter&nbsp;&nbsp;&nbsp;&nbsp;</button>
                </form><br>
                <form method="POST" action="{$WEB_BASE_URL}/index.php?controller=game&action=list&database={if isset($data)}{$data}{else}tpg{/if}&filter=filterParent">
					<div class="span3">
						<select name="filter" class="select" style="width: 100%;">
							<option value="0">-- Chọn Parent--</option>
							{foreach from=$gameCategoryArr item=gameCategory}
							<option value="{$gameCategory.id}" {if isset($filter)}{if $gameCategory.id eq $filter}Selected{/if}{/if}>{$gameCategory.name}</option>	
							{/foreach}
						</select>
					</div>&nbsp;&nbsp;&nbsp;
					<button class="btn btn-primary" type="submit">&nbsp;&nbsp;&nbsp;&nbsp;Fillter&nbsp;&nbsp;&nbsp;&nbsp;</button>
                </form><br>
                <form method="POST" action="{$WEB_BASE_URL}/index.php?controller=game&action=list&database={if isset($data)}{$data}{else}tpg{/if}&filter=type">
					<div class="span3">
						<select name="filterP" class="select" style="width: 100%;">
							<option value="0">-- Chọn Parent--</option>
							{foreach from=$gameCategoryArr item=gameCategory}
							<option value="{$gameCategory.id}" {if isset($filterP)}{if $gameCategory.id eq $filterP}Selected{/if}{/if}>{$gameCategory.name}</option>	
							{/foreach}
						</select>
					</div>&nbsp;&nbsp;&nbsp;
					<div class="span3">
						<select name="filterType" class="select" style="width: 100%;">
							<option value="1" {if isset($filterType)}{if $filterType eq '1'}Selected{/if}{/if}>Sự Kiện</option>
							<option value="2" {if isset($filterType)}{if $filterType eq '2'}Selected{/if}{/if}>Hướng dẫn</option>
						</select>
					</div>&nbsp;&nbsp;&nbsp;
					<button class="btn btn-primary" type="submit">&nbsp;&nbsp;&nbsp;&nbsp;Fillter&nbsp;&nbsp;&nbsp;&nbsp;</button>
                </form><br>
			</div>
			<div class="btn-group" data-toggle="buttons-checkbox">
				<table>
					<tr>
						<td>
							<form method="POST" action="{$WEB_BASE_URL}/index.php?controller=game&action=list&database=tpg">
								<button type="submit" class="btn btn-primary {if isset($data) && $data eq 'tpg'}active{/if}">Thành Phố Game</button>
							</form>
						</td>
						<!-- <td>
							<form method="POST" action="{$WEB_BASE_URL}/index.php?controller=game&action=list&database=cgmb">
								<button type="submit" class="btn btn-primary {if isset($data) && $data eq 'cgmb'}active{/if}">Chơi Game Mobi</button>
							</form>
						</td> -->
						<td>
							<form method="POST" action="{$WEB_BASE_URL}/index.php?controller=game&action=list&database=mmbg">
								<button type="submit" class="btn btn-primary {if isset($data) && $data eq 'mmbg'}active{/if}" >My Mobi Game</button>
							</form>
						</td>
						<!-- <td>
							<form method="POST" action="{$WEB_BASE_URL}/index.php?controller=game&action=list&database=nsgt">
								<button type="submit" class="btn btn-primary {if isset($data) && $data eq 'nsgt'}active{/if}" >Ngôi Sao Game Thủ</button>
							</form>
						</td> -->
						<td>
							<form method="POST" action="{$WEB_BASE_URL}/index.php?controller=game&action=add">
								<button type="submit" class="btn btn-primary" >Thêm Game</button>
							</form>
						</td>
						<td>
							<form method="POST" action="{$WEB_BASE_URL}/index.php?controller=game&action=filter">
								<button type="submit" class="btn btn-primary" onclick="return confirm('Bạn có muốn clean Event tiếp không?')">Clean Event</button>
							</form>
						</td>
						<td>
							<form method="POST" action="{$WEB_BASE_URL}/index.php?controller=game&action=list&database=mobile">
								<button type="submit" class="btn btn-warning {if isset($data) && $data eq 'mobile'}active{/if}" >List Game Mobile</button>
							</form>
						</td>
						<td>
							<form method="POST" action="{$WEB_BASE_URL}/index.php?controller=game&action=addMobile">
								<button type="submit" class="btn btn-warning" >Thêm Game Mobile</button>
							</form>
						</td>
						<td>
							<form method="POST" action="{$WEB_BASE_URL}/index.php?controller=game&action=addMMBG">
								<button type="submit" class="btn btn-success" >Thêm Game MyMobiGame</button>
							</form>
						</td>
					</tr>
				</table>
			</div>
            <div class="head dblue">
                <div class="icon"><span class="ico-layout-9"></span></div>
                <h2>Danh Sách Game</h2>
                <ul class="buttons">
                    <li><a href="#" onClick="source('table_sort_pagination'); return false;">
                        <div class="icon"><span class="ico-info"></span></div>
                    </a></li>
                </ul>
            </div>
            <div class="data-fluid">
                <table class="table lcnp" id="listGame" cellpadding="0" cellspacing="0" width="100%">
                    <thead>
                        <tr>
                            
                            <th>ID</th>
                            <th>Name</th>
                            <th>Medium Name</th>
                            <th>Unique Name</th>
                            <th>Images</th>
                            <th>Parent</th>
                            <th>Order</th>
                            <th>isEvent</th>
                            <th>HotStar</th>
                            <th>Type</th>
                            <th>link_canonical</th>
                            <th width="80" class="TAC">Actions</th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody>
                    {foreach from=$gameArr item=game}
                        <tr id="{$game.id}" class="edit_tr">
                            
                            <td>{$game.id}</td>
                            <td width="10%">
                            	<span id="name_{$game.id}" class="text">
	                            	{$game.name}
                            	</span>
                            	<textarea rows="2" cols="2" class="editbox" id="name_input_{$game.id}" style="display: none;height: 100px; width: 80px;">{$game.name}</textarea>
                            </td>
                            <td width="15%">
                            	<span id="mediumname_{$game.id}" class="text">
	                            	{$game.mediumName}
                            	</span>
                            	<textarea rows="2" cols="2" class="editbox" id="mediumname_input_{$game.id}" style="display: none;height: 100px; width: 110px;">{$game.mediumName}</textarea>                                          
                            </td>
                            <td width="15%">
                            	<span id="uniquename_{$game.id}" class="text">
	                            	{$game.unique_name}
                            	</span>
                            	<textarea rows="2" cols="2" class="editbox" id="uniquename_input_{$game.id}" style="display: none;height: 100px; width: 110px;">{$game.unique_name}</textarea>
                            </td>
                            <td width="10%"><img alt="" src="{$WEB_BASE_URL}/../images/{$game.largeImage}"></td>
                            
                            <td width="10%">{$game.parent}</td>
                            <td width="5%">
	                            <span id="gameorder_{$game.id}" class="text">
	                            	{if $game.order ge 1}<strong style="color:blue;">{$game.order}</strong>{else} 0{/if}
                            	</span>
                            	<input type="text" value="{$game.order}" class="editbox" id="gameorder_input_{$game.id}" style="display: none;"/>
                            </td>
                            <td width="5%">
                            	<span id="isevent_{$game.id}" class="text">
	                            	{if $game.isEvent eq 1 } Hiện {else} Ẩn {/if}
                            	</span>
                            	<select name="isEvent" class="editbox" id="isevent_input_{$game.id}" style="display: none;">
									<option value="1" {if $game.isEvent eq '1'}Selected{/if}>Hiện</option>
									<option value="0" {if $game.isEvent eq '0'}Selected{/if}>Ẩn</option>
								</select>
                            </td>
                            <td width="5%">
                            	<span id="hotstar_{$game.id}" class="text">
	                            	{if $game.hot_star eq 5 } Hiện {else} Ẩn {/if} 
                            	</span>
                            	<select name="hos_star" class="editbox" id="hotstar_input_{$game.id}" style="display: none;">
									<option value="5" {if $game.hot_star eq '5'}Selected{/if}>Hiện</option>
									<option value="0" {if $game.hot_star eq '0'}Selected{/if}>Ẩn</option>
								</select>
                            </td>
                            <td width="5%">
                            	<span id="type_{$game.id}" class="text">
	                            	{if $game.type eq 1 } Sự Kiện {else} Hướng Dẫn {/if} 
                            	</span>
                            	<select name="type" class="editbox" id="type_input_{$game.id}" style="display: none;">
									<option value="1" {if $game.type eq '1'}Selected{/if}>Sự Kiện</option>
									<option value="2" {if $game.type eq '2'}Selected{/if}>Hướng Dẫn</option>
								</select>
                            </td>
                            <td width="15%">
                            	<span id="link_canonical_{$game.id}" class="text">
	                            	{$game.link_canonical}
                            	</span>
                            	<textarea rows="2" cols="2" class="editbox" id="link_canonical_input_{$game.id}" style="display: none;height: 100px; width: 110px;">{$game.link_canonical}</textarea>                                          
                            </td>
                            <td>
                                <a href="{$WEB_BASE_URL}/index.php?controller=game&action=update&database={if isset($data)}{$data}{else}tpg{/if}&id={$game.id}" class="button green">
                                    <div class="icon"><span class="ico-pencil"></span></div>
                                </a>
                                <a href="{$WEB_BASE_URL}/index.php?controller=game&action=delete&database={if isset($data)}{$data}{else}tpg{/if}&id={$game.id}" class="button red" onclick="return confirm('Bạn có muốn xóa tiếp không?')">
                                    <div class="icon"><span class="ico-remove"></span></div>
                                </a>
                            </td>
                            <td>
								<form method="POST" action="{$WEB_BASE_URL}/index.php?controller=game&action=sendMail&id={$game.id}">
									<button type="submit" class="btn btn-primary">SEND</button>
								</form>
							</td>
                            
                        </tr>
                    {/foreach}
                    </tbody>
                </table>
                <span style="color:blue">{if isset($count)}{$count}{/if}</span>
                <div class="pagination pagination-centered">
                        {if isset($pageFirst) && isset($pagePrev) && isset($pageList) && isset($pageNext) && isset($pageLast)}
	                	<ul>
	                		<li class="disabled">{$pageFirst}</li>
	                		<li class="active">{$pagePrev}</li>
	                		<li>{$pageList}</li>
	                		<li>{$pageNext}</li>
	                		<li>{$pageLast}</li>
	                    </ul>
	                    {/if}
                    </div>
            </div>
        </div>
    </div>
</div>

{/block}
